const utils = {
  toast(title = '数据加载失败...', duration = 2000) {
    wx.showToast({
      title,
      icon: 'none',
      mask: true,
      duration
    })
  },
  getRandomIntInclusive(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值，含最小值
  },
  formatDate(time) {
    time = new Date(time)
    const year = time.getFullYear()
    const month = time.getMonth() + 1
    const date = time.getDate()
    return [year, month, date].map(item => item.toString().padStart(2, 0)).join('-')
  },
  isTabBarPage(path = '') {
    console.log(__wxConfig)
    const tabBarList = __wxConfig.tabBar.list
    const tabBarPages = tabBarList.map(({
      pagePath
    }) => {
      return pagePath.split('.')[0]
    })
    return tabBarPages.includes(path)
  }
}

// 如何创建全局方法
// Vue.prototype.xxx = xxx
// wx 是一个内置的，顶级全局的对象
wx.utils = utils

export default utils